﻿package mortal.game.view.shop
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.game.view.shopMall.view.*;
    import mortal.mvc.core.*;

    public class BuyAdvanceItemPart extends GSprite
    {
        private var _shopItem:ShopSellItem;
        private var _propName:GTextFiled;
        private var _numericStepper:GNumericStepper;
        private var _btnBindGold:GRadioButton;
        private var _btnUnBindGold:GRadioButton;
        private var _buyBtn:GLoadingButton;
        private var _priceIcon1:GBitmap;
        private var _priceIcon2:GBitmap;
        private var _itemData:ItemData;

        public function BuyAdvanceItemPart()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._shopItem = UICompomentPool.getUICompoment(ShopSellItem);
            this._shopItem.isShowLock = true;
            this._shopItem.x = 11;
            this._shopItem.y = 33;
            this._shopItem.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this.addChild(this._shopItem);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 15;
            _loc_1.bold = true;
            this._propName = UIFactory.gTextField("", 0, 2, 235, 25, this, _loc_1, true);
            _loc_1.align = TextFormatAlign.LEFT;
            _loc_1.size = 12;
            _loc_1.bold = false;
            this._btnBindGold = UIFactory.radioButton(Language.getString(35532), 90, 32, 140, 22, this);
            this._btnBindGold.setStyle("textFormat", _loc_1);
            this._btnBindGold.groupName = "shopGigtBuy";
            this._btnBindGold.selected = true;
            this._btnBindGold.configEventListener(MouseEvent.CLICK, this.changeGoldType);
            this._btnUnBindGold = UIFactory.radioButton(Language.getString(35532), 90, 56, 140, 22, this);
            this._btnUnBindGold.setStyle("textFormat", _loc_1);
            this._btnUnBindGold.groupName = "shopGigtBuy";
            this._btnUnBindGold.configEventListener(MouseEvent.CLICK, this.changeGoldType);
            _loc_1.align = TextFormatAlign.RIGHT;
            this._numericStepper = UIFactory.gNumericStepper(91, 82, 50, 20, this, 99, 1, "NumericStepper", _loc_1);
            this._numericStepper.configEventListener(Event.CHANGE, this.updateNum);
            this._numericStepper.value = 1;
            this._buyBtn = UIFactory.gLoadingButton(ResFileConst.ShopMallBuyBtn, 175, 81, 51, 24, this);
            this._buyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._priceIcon1 = UIFactory.gBitmap("", 200, 32, this);
            this._priceIcon2 = UIFactory.gBitmap("", 200, 56, this);
            this._priceIcon1.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(EPriceUnit._EPriceUnitGoldBind));
            this._priceIcon2.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(EPriceUnit._EPriceUnitGold));
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.updateNum);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.MoneyUpdate, this.updateNum);
            this._shopItem.dispose(param1);
            this._shopItem = null;
            this._propName.dispose(param1);
            this._propName = null;
            this._numericStepper.dispose(param1);
            this._numericStepper = null;
            this._btnBindGold.dispose(param1);
            this._btnBindGold = null;
            this._btnUnBindGold.dispose(param1);
            this._btnUnBindGold = null;
            this._buyBtn.dispose(param1);
            this._buyBtn = null;
            this._priceIcon1.dispose(param1);
            this._priceIcon1 = null;
            this._priceIcon2.dispose(param1);
            this._priceIcon2 = null;
            this._itemData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            this._shopItem.shopItemData.num = this._numericStepper.value;
            Dispatcher.dispatchEvent(new DataEvent(EventName.BuyItem, this._shopItem));
            return;
        }// end function

        private function updateNum(param1:Object = null) : void
        {
            var _loc_3:GTextFormat = null;
            var _loc_2:* = this._shopItem.shopItemData.prize * this._numericStepper.value;
            if (Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitGoldBind, _loc_2, null, false))
            {
                _loc_3 = GlobalStyle.textFormatBai;
                _loc_3.align = AlignMode.RIGHT;
            }
            else
            {
                _loc_3 = GlobalStyle.textFormatHong;
                _loc_3.align = AlignMode.RIGHT;
            }
            this._btnBindGold.setStyle("textFormat", _loc_3);
            this._btnBindGold.label = Language.getString(35533) + _loc_2;
            if (Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitGold, _loc_2, null, false))
            {
                _loc_3 = GlobalStyle.textFormatBai;
                _loc_3.align = AlignMode.RIGHT;
            }
            else
            {
                _loc_3 = GlobalStyle.textFormatHong;
                _loc_3.align = AlignMode.RIGHT;
            }
            this._btnUnBindGold.setStyle("textFormat", _loc_3);
            this._btnUnBindGold.label = Language.getString(35533) + _loc_2;
            return;
        }// end function

        private function changeGoldType(event:MouseEvent = null) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (this._btnBindGold.selected)
            {
                _loc_2 = ItemsUtil.isBind(this._itemData) ? (this._itemData.itemCode) : (this._itemData.itemInfo.codeUnbind);
                _loc_3 = 1006;
            }
            else
            {
                _loc_2 = ItemsUtil.isBind(this._itemData) ? (this._itemData.itemInfo.codeUnbind) : (this._itemData.itemCode);
                _loc_3 = 1003;
            }
            var _loc_4:* = ShopConfig.instance.getShopSellByItemCodeAndShopCode(_loc_2, _loc_3);
            this._shopItem.shopItemData = new ShopItemData(_loc_4);
            this._shopItem.shopItemData.type = this._shopItem.shopItemData.tShopSell.isBindMoney;
            return;
        }// end function

        public function set num(param1:int) : void
        {
            this._numericStepper.value = param1;
            this.updateNum();
            return;
        }// end function

        public function set data(param1:ItemData) : void
        {
            this._itemData = param1;
            this._btnBindGold.selected = true;
            this.changeGoldType();
            this._propName.htmlText = ItemsUtil.getItemName(this._shopItem.itemData);
            this.updateNum();
            return;
        }// end function

    }
}
